package flex.cc.util;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import flex.cc.basicinformation.dao.ValueAddedServiceProviderConfigDao;
import flex.cc.basicinformation.entity.ValueAddedServiceProviderConfigEntity;
import flex.cc.system.dao.DictCodeDao;
import flex.cc.system.entity.DictCodeEntity;

/**
 * 接口配置由yml获取改为db获取  工具类
 * @author R
 */
@Component
public class APIConfigUtil {
    @Resource
    private ValueAddedServiceProviderConfigDao serviceProviderConfigDao;
    @Resource
    private DictCodeDao dictCodeDao;
	/**
	 * 根据服务商和接口类型获取接口参数
	 * @param provider 服务商id
	 * @param apiType 接口类型
	 * @return
	 */
	public String getApiConfig(String provider,String apiType){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("spid", provider);
		params.put("type", apiType);
		ValueAddedServiceProviderConfigEntity serviceProviderConfigEntity = serviceProviderConfigDao.getOneByParams(params);
		if(serviceProviderConfigEntity==null){
			return "";
		}else{
			return serviceProviderConfigEntity.getValue();
		}
	}
	
	/**
	 * 上游接口配置 再字典表内维护
	 * @param type 配置类型
	 * @return
	 */
	public String getSYApiConfig(String type){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("typeCode", "syAPIConfig");
		params.put("code", type);
		DictCodeEntity dictCodeEntity = dictCodeDao.getOneByParams(params);
		if(dictCodeEntity==null){
			return "";
		}else{
			return dictCodeEntity.getValue();
		}
	}
	
	
	/**
	 * 单项类接口配置 在字典表内维护
	 * @param type 配置类型
	 * @return
	 */
	public String getSingleApiConfig(String type){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("typeCode", "singleApi");
		params.put("code", type);
		DictCodeEntity dictCodeEntity = dictCodeDao.getOneByParams(params);
		if(dictCodeEntity==null){
			return "";
		}else{
			return dictCodeEntity.getValue();
		}
	}
}
